home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program computes a five point smoothing algorithm, just like ex3.d,
- * except that it deals with matrix sizes which are not a multiple of the
- * number of processors. It uses the include file d "map.c" to do
- * this. */
-
- #include "dino.h"
-
- #define max(x,y) (x > y ? x : y)
- #define min(x,y) (x < y ? x : y)
-
- #define M 11
- #define N 8
- #define P1 3
- #define P2 3
-
- environment node[P1:id1][P2:id2] {
-
- #include "../inc/map.c"
-
- /* ==> Includes the map.c include file. Since
- this file contains code, it must be
- included within an environment. See
- the listing after example 2.4. */
-
- composite smooth (a, in iter)
- double distributed a[M][N] map FivePt;
- int iter;
-
- {
- int i, j, k; /* Looping variables */
- map_var a1, a2;
-
- /* Setup map_var's a1 and a2 for the complete data structure A */
- set_map_var (M, P1, id1, 1, 1, &a1);
- set_map_var (N, P2, id2, 1, 1, &a2);
-
- /* ==> Illustrates the use of set_map_var
- with overlaps (see examples/matvec/ex4.d
- for an explanation of set_map_var). */
-
- /* Limit the map_var's to not use the edges of A, which are boundary
- * conditions that don't change */
-
- limit_map_var (1, /* Minimum data used */
- M-2, /* Maximum data used */
- &a1); /* Address of the map_var */
-
- /* ==> This function, defined in map.c, limits
- the map_var a1 to the range <1,M-2>.
- This means that the edge data is not
- send and/or received when map_var a1
- is used. */
-
- limit_map_var (1, N-2, &a2);
-
- /* Repeat the smoothing process iter times */
- for (i = 0; i < iter; i++) {
-
- /* Send out your data and receive it back again, if not the first
- * iteration */
- if (i != 0) {
- a[<a1.left,a1.right>][<a2.left,a2.right>]# =
- a[<a1.left,a1.right>][<a2.left,a2.right>];
- a[<a1.lover,a1.rover>][<a2.lover,a2.rover>]#;
- }
-
- /* Perform the computation, but only on non-edge elements */
- for (j = a1.left; j <= a1.right; j++)
- for (k = a2.left; k <= a2.right; k++)
- a[j][k] = (a[j][k-1] + a[j][k+1] + a[j-1][k] + a[j+1][k]) / 4;
-
- }
- }
- }
-
- environment host {
-
- void main ()
-
- {
- double a[M][N]; /* Input data */
- int iter; /* Holds the iteration count */
-
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] */
- for (i = 0; i < M; i++)
- for (j = 0; j < N; j++)
- a[i][j] = (i + 1)*(j + 1);
- for (i = 1; i < M - 1; i++)
- for (j = 1; j < N - 1; j++)
- a[i][j] = 0;
-
- /* Set up the variable which will contain the number of iterations */
- iter = 100;
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%7.2f", a[i][j]);
- printf ("\n");
- }
-
- /* Perform the computation */
- smooth (a[][], iter)#;
-
- /* Printout the results */
- printf ("Result data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%7.2f", a[i][j]);
- printf ("\n");
- }
- }
- }
-